<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>

    <link rel="stylesheet" type="text/css" href="/static/lib/datatables/1.10.15/jquery.dataTables.css">
    <div th:include="admin/common :: head"></div>

    <link rel="stylesheet" href="/static/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <style type="text/css">
        th {
            text-align: center;
        }
        .table td {
            text-align: center;
        }
    </style>
    <title>我的桌面</title>
</head>

<body>

<div class="Huialert Huialert-info" style="text-align: center"><i class="Hui-iconfont">&#xe6a6;</i>
    根据类目查询所有课程
</div>

<div style="margin-left:150px;">
    <div class="pd-20">

        <form id="searchForm" action="/admin/course/search">
            <div class="text-c"> 创建日期范围：
                <input type="text" name="start_time" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}'})" id="logmin" class="input-text Wdate" style="width:160px;">
                -
                <input type="text" name="end_time" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d'})" id="logmax" class="input-text Wdate" style="width:160px;">
                <input type="text" name="name" id="" placeholder=" 课程名称" style="width:150px" class="input-text">
                <button  class="btn btn-success" type="submit" id="submit"><i class="Hui-iconfont">&#xe665;</i> 搜课程</button>
                <input type="text" hidden="hidden" id="classify" name="classify" th:value="${classify}">
            </div>
        </form>

        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-danger-outline radius"  onclick="datadel()" href="javascript:;" >
                <i class="Hui-iconfont">&#xe6e2;</i>批量删除</a>

                <a class="btn btn-secondary-outline radius" th:href="@{/admin/course/courseAdd}">
                <i class="Hui-iconfont">&#xe600;</i>添加课程</a></span>

                    <a class="btn btn-success-outline radius" th:href="@{/admin/course/exportExcel/0}">
                        <i class="Hui-iconfont">&#xe644;</i>导出课程</a></span>

                    <a class="btn btn-success-outline radius"onclick="product_add()" href="javascript:;">
                <i class="Hui-iconfont">&#xe645;</i>导入课程</a></span>
            </span>

            <span class="r">共有数据：<strong th:text="${courseList.size()}"></strong> 条</span>
        </div>

        <div class="mt-20">
            <table id="sheetList" class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="5"><input type="checkbox" name="" value=""></th>
                    <th width="100">课程名称</th>
                    <th width="100">课程封面</th>
                    <th width="40">教师详情</th>
                    <th width="40">类型</th>
                    <th width="40">学习人数</th>
                    <th width="40">权重</th>
                    <th width="100">创建时间</th>
                    <th width="40">是否上架</th>
                    <th width="80">操作</th>
                </tr>
                </thead>

                <tbody>
                <tr  th:each="course,courseList : ${courseList}" >
                    <td><input type="checkbox" th:value="${course.id}"  name=""></td>

                    <td  >
                        <u style="cursor:pointer" class="text-primary" th:text="${course.name}"
                           th:onclick="|course_show('查看课程','/admin/course/courseDetail/${course.id }')|">
                        </u>
                    </td>

                    <td><img width="100" height="100" class="picture-thumb"th:src="${course.picture}"></td>

                    <td ><span class="label label-success radius">
					<a style="text-decoration:none" class="ml-5"
                       th:onclick="|userDetail('教师详情','/admin/user/userDetail/${course.userId }','450','450')|"
                       href="javascript:;" title="教师详情">教师详情</a></span>
                    </td>

                    <td th:text="${course.subClassifyName}"></td>

                    <td th:text="${course.studyCount}"></td>

                    <td><input type="text" th:id="'weight_'+${course.id}" class="input-text text-c" th:value="${course.weight}"></td>

                    <th class="text-c" th:text="${#dates.format(course.createTime, 'yyyy-MM-dd HH:mm:ss')}"></th>

                    <td th:if="${course.onsale}==0" class="td-status">
                        <span class="label label-info radius">未上架</span>
                    </td>
                    <td th:if="${course.onsale}==1" class="td-status" >
                        <span class="label label-success radius">已上架</span>
                    </td>


                    <td class="td-manage">

                        <a title="下架" style="text-decoration:none" href="javascript:;"
                           th:onclick="|javascript:course_stop(this,'${course.id }')|"  >
                            <i class="Hui-iconfont" th:if="${course.onsale}==1">&#xe6de;</i></a>
                        <a title="上架" style="text-decoration:none" href="javascript:;"
                           th:onclick="|javascript:course_start(this,'${course.id }')|"  >
                            <i class="Hui-iconfont"th:if="${course.onsale}==0">&#xe603;</i></a>

                        <a title="编辑"  th:onclick="|javascript:course_edit('编辑课程基本信息','/admin/course/courseEditPage/${course.id}','4','800','600')|"
                           class="ml-5" style="text-decoration:none">
                            <i class="Hui-iconfont">&#xe6df;</i></a>
                        <a title="删除" href="javascript:;"class="ml-5" style="text-decoration:none"
                           th:onclick="|javascript:course_del(this,'${course.id }')|">
                            <i class="Hui-iconfont">&#xe6e2;</i></a>
                    </td>

                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>






<footer th:include="admin/common :: footer"></footer>
<script type="text/javascript" src="/static/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/static/lib/datatables/1.10.15/jquery.dataTables.js"></script>
<script type="text/javascript" src="/static/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">

    $(function(){
        $('.table-sort').dataTable({
            "aaSorting":
                [
                    [
                        1,"desc"
                    ]
                ],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[0,2]}// 制定列不参与排序
            ]
        });


        //监听权重input改变事件
        $(".input-text").on("change",function(){
            debugger;
            var weight =this.value;
            var id=this.id.substring(7);
            $.ajax({
                url : "/admin/course/updateWeight/"+id+"/"+weight,
                type : "get",
                //dataType : "json",
                processData : false, // 告诉jQuery不要去处理发送的数据
                contentType : false, // 告诉jQuery不要去设置Content-Type请求头
                success: function(data){
                    if (data.code === 200){
                        layer.msg('修改成功!',{icon: 6,time:1000})
                    }else{
                        layer.msg("修改失败,请输入正确的格式!", {icon: 5, time: 2000});
                    }
                }
            });

        })

    });

    /*课程基本信息-编辑*/
    function course_edit(title,url,id,w,h){
        layer_show(title,url,w,h);
    }

    /*课程详情页面*/
    function course_show(title,url,w,h){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    /*用户详情页面*/
    function userDetail(title,url,w,h){
        layer_show(title,url,w,h);
    }

    /*用户-停用*/
    function course_stop(obj,id){
        layer.confirm('确认下架吗？',function(index){
            $.ajax({
                type: "POST",
                url: "/admin/course/courseStop",
                data: {
                    id:id,
                },
                success: function(data){
                    //var data = eval('(' + data + ')');
                    if (data.code === 200){
                        $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" ' +
                            'onClick="course_start(this,'+id+')" href="javascript:;" title="上架">' +
                            '<i class="Hui-iconfont">&#xe603;</i></a>');
                        $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
                        $(obj).remove();
                        layer.msg('已下架!',{icon: 5,time:2000});
                        //location.replace(location.href);
                    }else{
                        alert("发生错误!请重新操作");
                    }
                }
            });
        });

    }

    /*用户-启用*/
    function course_start(obj,id){

        layer.confirm('确认上架吗？',function(index){
            $.ajax({
                type: "POST",
                url: "/admin/course/courseStart",
                data: {
                    id:id,
                },
                success: function(data){
                    //var data = eval('(' + data + ')');
                    if (data.code === 200){
                        $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" ' +
                            'onClick="course_stop(this,'+id+')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
                        $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已上架</span>');
                        $(obj).remove();
                        layer.msg('已上架!',{icon: 6,time:2000});
                        //location.replace(location.href);
                    }else{
                        alert("发生错误!请重新操作");
                    }
                }
            });
        });
    }

    /*用户-删除*/
    function course_del(obj,id){
        layer.confirm('逻辑删除一门课程，确认要删除吗？',function(index){
            $.ajax({
                type: "POST",
                url: "/admin/course/logicDelete",
                data: {
                    id:id,
                },
                success: function(data){
                    //var data = eval('(' + data + ')');
                    if (data.code === 200){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:2000});
                        /* location.href="${pageContext.request.contextPath}/teacher/teacherList" */
                        reloadTable();
                    }else{
                        alert("发生错误!请重新操作");
                    }
                }
            });
        });
    }
</script>
</body>
</html>